#include "CF_Core.h"

//================================================
CCF_Camera::CCF_Camera(void)
{
  m_filedOfView = D3DX_PI / 4;
  m_nearDistance = 1.0f;
  m_farDistance = 1000.0f;

  m_position = D3DXVECTOR3( 0, 0, -5 );
  m_direction = D3DXVECTOR3( 0, 0, 1 );
  m_up = D3DXVECTOR3( 0, 1, 0 );
}
//================================================
CCF_Camera::~CCF_Camera(void)
{
}
//================================================
void CCF_Camera::SetCamera( D3DXVECTOR3 pos, D3DXVECTOR3 dir, D3DXVECTOR3 up )
{
  m_position = pos;
  D3DXVec3Normalize( &m_direction, &dir );
  D3DXVec3Normalize( &m_up, &up );
}

//================================================
D3DXVECTOR3 CCF_Camera::GetPosition()
{
  return m_position;
}
//================================================
D3DXMATRIX* CCF_Camera::CalcViewMatrix()
{
  D3DXVECTOR3 target = m_position + m_direction;
  D3DXMatrixLookAtLH( &m_result, &m_position, &target, &m_up );

  return &m_result;
}
//================================================
D3DXMATRIX* CCF_Camera::CalcProjectionMatrix()
{
  D3DXMatrixPerspectiveFovLH( &m_projection, m_filedOfView,  1.0f, m_nearDistance, m_farDistance );

  return &m_projection;
}
//================================================
D3DXMATRIX* CCF_Camera::CalcInvertViewMatrix()
{
  D3DXMatrixInverse( &m_invertView, NULL, &m_result );

  return &m_invertView;
}
